import ddt
import time
import unittest
from page.reception.login_page import LoginPage
from page.reception.index_page import IndexPage
from page.reception.receiving_address_pages import ReceivingAddressPages
from common.functions import browser_operation, host


@ddt.ddt()
class ReceivingAddressTastCase(unittest.TestCase):

    @classmethod
    def setUpClass(cls) -> None:
        # TODO 打开浏览器，登录账户
        driver = browser_operation()
        # 创建LoginPage对象
        cls.receiving_addr = ReceivingAddressPages(driver)
        cls.index = IndexPage(driver)
        cls.login = LoginPage(driver)
        url = host + 'user.php'
        cls.login.get_website(url)
        cls.login.input_username('豆芽纸')
        cls.login.input_password('123456')
        cls.login.btn_login()


    def test01_receiving_address(self):
        # TODO 点击：收货地址 按钮
        time.sleep(1)
        self.receiving_addr.btn_receiving_address()

        # TODO 定位选择省份，添加：province
        time.sleep(1)
        self.receiving_addr.select_province('湖北省')

        # TODO 定位选择市，添加：city
        time.sleep(1)
        self.receiving_addr.select_city('孝感市')

        # TODO 定位选择区，添加：area
        time.sleep(1)
        self.receiving_addr.select_district('孝南区')

        # TODO 定位收货人姓名，添加：consignee_name
        time.sleep(1)
        self.receiving_addr.consignee_name('胖豆芽')

        # TODO 定位详细地址，添加：detailed_address
        time.sleep(1)
        self.receiving_addr.detailed_addr('曙光星城A区')

        # TODO 定位电话，添加：telephone
        time.sleep(1)
        self.receiving_addr.telephone('027-28865253')

        # TODO 定位电子邮件地址，添加：e-mail_address
        time.sleep(1)
        self.receiving_addr.email_addr('646785213@qq.com')

        # TODO 定位邮政编码，添加：postal_code
        time.sleep(1)
        self.receiving_addr.postal_code('410009')

        # TODO 定位手机，添加：mobile_phone
        time.sleep(1)
        self.receiving_addr.mobile_phone('13688888888')

        # TODO 定位新增收货地址按钮，添加：
        time.sleep(1)
        self.receiving_addr.add_receiving_address()

        # # TODO 断言  确认：是否存在：确认修改按钮
        # add_assert =self.receiving_addr.get_element_text((By.XPATH,'/html/body/div[6]/div[2]/div/div/div/form[1]/table/tbody/tr[5]/td[2]/input[1]'))
        # self.assertEqual('确认修改',add_assert)

    def test02_del_address(self):
        # TODO 删除地址
        time.sleep(1)
        self.receiving_addr.del_addr()
        time.sleep(1)
        self.receiving_addr.choice_alert()

        # # TODO 断言  确认：是否存在：删除按钮
        # del_assert =self.receiving_addr.get_element_text((By.XPATH,'/html/body/div[6]/div[2]/div/div/div/form[1]/table/tbody/tr[5]/td[2]/input[2]'))
        # self.assertEqual('删除',del_assert)


    @classmethod
    def tearDownClass(cls) -> None:
        # TODO 退出并关闭浏览器
        time.sleep(1)
        cls.index.logout()
        cls.receiving_addr.quit()

if __name__ == '__main__':
    unittest.main(verbosity=2)